package com.zjuee.web.tporder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.service.*;
import com.zjuee.base.dto.common.tporder.*;
import com.zjuee.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Slf4j
@RestController
@RequestMapping(Common.Service.ZJUEE_CO_MAIN_TPORDER_URL_PREFIX)
public class TPOrderController  {

    @Resource
    private TransAffairsApplyService transAffairsApplyService;

    @Resource
    private TransAffairsReplyService transAffairsReplyService;

    @Resource
    private TransOrderApplyService transOrderApplyService;

    @Resource
    private TransOrderReplyService transOrderReplyService;

    @Resource
    private TransOrderSolidService transOrderSolidService;

    @PostMapping("/test1")
    public R transAffairsApplyList1() {
       return R.fail("1");
    }
    /**
     * 跨省转移-跨省转出查询
     *
     * @param transAffairsApplyDto Dto
     * @return Page<WkTransAffairsApplyVo>
     */
    @PostMapping("/transAffairsApplyList")
    public R<Page<WkTransAffairsApplyVo>> transAffairsApplyList(TransAffairsApplyDto transAffairsApplyDto) {
        try {
            Page<WkTransAffairsApplyVo> page = transAffairsApplyService.list(transAffairsApplyDto);
            if (null != page) {
                return R.ok(page);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
        return R.fail("记录不存在！");
    }
    /**
     * 跨省转移-跨省转出新增
     *
     * @param wkTransAffairsApplyVo
     * @return R
     */
    @PostMapping("/addTransAffairsApply")
    public R addTransAffairsApply(WkTransAffairsApplyVo wkTransAffairsApplyVo) {
        return R.ok(transAffairsApplyService.add(wkTransAffairsApplyVo));
    }
    /**
     * 跨省转移-跨省转出查询-详情
     *
     * @param id
     * @return WkTransAffairsApplyVo
     */
    @GetMapping("/transAffairsApply/{id}")
    public R<WkTransAffairsApplyVo> getTransAffairsApply(@NotNull Long id) {
        try{
            WkTransAffairsApplyVo applyVo = transAffairsApplyService.getTransAffairsApply(id);
            return R.ok(applyVo);
        }catch (Exception e){
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }
    /**
     * 跨省转移-跨省转入查询
     *
     * @param transAffairsReplyDto Dto
     * @return Page<WkTransAffairsReplyVo>
     */
    @PostMapping("/transAffairsReplyList")
    public R<Page<WkTransAffairsReplyVo>> transAffairsReplyList(TransAffairsReplyDto transAffairsReplyDto) {
        try {
            Page<WkTransAffairsReplyVo> page = transAffairsReplyService.list(transAffairsReplyDto);
            if (null != page) {
                return R.ok(page);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
        return R.fail("记录不存在！");
    }


    /**
     * 跨省转移-跨省转入查询-详情
     *
     * @param id
     * @return WkTransAffairsReplyVo
     */
    @GetMapping("/transAffairsReply/{id}")
    public R<WkTransAffairsReplyVo> getTransAffairsReply(@NotNull Long id) {
        try{
            WkTransAffairsReplyVo transAffairsReply = transAffairsReplyService.getTransAffairsReply(id);
            return R.ok(transAffairsReply);
        }catch (Exception e){
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }
    /**
     * 跨省转移-跨省转出联单查询
     *
     * @param transOrderApplyDto Dto
     * @return Page<WkTransOrderApplyVo>
     */
    @PostMapping("/transOrderApplyList")
    public R<Page<WkTransOrderApplyVo>> transOrderApplyList(TransOrderApplyDto transOrderApplyDto) {
        try {
            Page<WkTransOrderApplyVo> page = transOrderApplyService.list(transOrderApplyDto);
            if (null != page) {
                return R.ok(page);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
        return R.fail("记录不存在！");
    }
    /**
     * 跨省转移-跨省转出联单新增
     *
     * @param wkTransOrderApplyVo
     * @return R
     */
    @PostMapping("/addTransOrderApply")
    public R addTransOrderApply(WkTransOrderApplyVo wkTransOrderApplyVo) {
        return R.ok(transOrderApplyService.add(wkTransOrderApplyVo));
    }
    /**
     * 跨省转移-跨省转出联单查询-详情
     *
     * @param id
     * @return WkTransOrderApplyVo
     */
    @GetMapping("/transOrderApply/{id}")
    public R<WkTransOrderApplyVo> getTransOrderApply(@NotNull Long id) {
        try{
            WkTransOrderApplyVo transOrderApply = transOrderApplyService.getTransOrderApply(id);
            return R.ok(transOrderApply);
        }catch (Exception e){
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }
    /**
     * 跨省转移-跨省转入联单查询
     *
     * @param transOrderReplyDto Dto
     * @return Page<WkTransOrderReplyVo>
     */
    @PostMapping("/transOrderReplyList")
    public R<Page<WkTransOrderReplyVo>> transOrderReplyList(TransOrderReplyDto transOrderReplyDto) {
        try {
            Page<WkTransOrderReplyVo> page = transOrderReplyService.list(transOrderReplyDto);
            if (null != page) {
                return R.ok(page);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
        return R.fail("记录不存在！");
    }

    /**
     * 跨省转移-跨省转入联单更新
     *
     * @param wkTransOrderReplyVo
     * @return R
     */
    @PostMapping("/updateTransOrderReply")
    public R updateTransOrderReply(WkTransOrderReplyVo wkTransOrderReplyVo) {
        return R.ok(transOrderReplyService.update(wkTransOrderReplyVo));
    }

    /**
     * 跨省转移-跨省转入联单查询-详情
     *
     * @param id
     * @return WkTransOrderReplyVo
     */
    @GetMapping("/transOrderReply/{id}")
    public R<WkTransOrderReplyVo> getTransOrderReply(@NotNull Long id) {
        try{
            WkTransOrderReplyVo transOrderReply = transOrderReplyService.getTransOrderReply(id);
            return R.ok(transOrderReply);
        }catch (Exception e){
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }
    /**
     * 跨省转移-一般工业固废跨省转移备案查询
     *
     * @param transOrderSolidDto Dto
     * @return Page<WkTransOrderReplyVo>
     */
    @PostMapping("/transOrderSolidList")
    public R<Page<WkTransOrderSolidVo>> transOrderSolidList(TransOrderSolidDto transOrderSolidDto) {
        try {
            Page<WkTransOrderSolidVo> page = transOrderSolidService.list(transOrderSolidDto);
            if (null != page) {
                return R.ok(page);
            }
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.fail("记录不存在！");
    }
    /**
     * 跨省转移-一般工业固废跨省转移备案更新
     *
     * @param wkTransOrderSolidVo Dto
     * @return R
     */
    @PostMapping("/updateTransOrderSolid")
    public R updateTransOrderSolid(WkTransOrderSolidVo wkTransOrderSolidVo) {
        try {
            if (transOrderSolidService.update(wkTransOrderSolidVo)) {
                return R.ok();
            }
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.fail("更新失败！");
    }
    /**
     * 跨省转移-一般工业固废跨省转移备案新增
     *
     * @param wkTransOrderSolidVo Dto
     * @return R
     */
    @PostMapping("/addTransOrderSolid")
    public R addTransOrderSolid(WkTransOrderSolidVo wkTransOrderSolidVo) {
        return R.ok(transOrderSolidService.add(wkTransOrderSolidVo));
    }
    /**
     * 跨省转移-一般工业固废跨省转移备案查询-详情
     *
     * @param id
     * @return WkTransOrderSolidVo
     */
    @GetMapping("/transOrderSolid/{id}")
    public R<WkTransOrderSolidVo> getTransOrderSolid(@NotNull Long id) {
        try{
            WkTransOrderSolidVo transOrderSolid = transOrderSolidService.getTransOrderSolid(id);
            return R.ok(transOrderSolid);
        }catch (Exception e){
            e.printStackTrace();
            return R.fail(e.getMessage());
        }
    }


}
